/**
 * 共用部分
 */
// import store from '@/store'
import { isNull } from '@/utils/utils'
export const getHospitalCode = () => {
  return 'test' // store.state.user.userInfo.hospitalCode
}
// 设置院区级缓存
export const setLocalStorage = (key, data, hospitalCode = getHospitalCode()) => {
  console.log('hospitalCode', hospitalCode)
  localStorage.setItem(`${key}-${hospitalCode}`, data)
}
// 获取院区级缓存
export const getLocalStorage = (key, hospitalCode = getHospitalCode()) => {
  // 院区缓存没有，历史缓存有，先取历史缓存，不然更新到医院，缓存都要重新设置，会被说的
  if (isNull(localStorage.getItem(`${key}-${hospitalCode}`)) && !isNull(localStorage.getItem(`${key}`))) {
    return localStorage.getItem(`${key}`)
  }
  return localStorage.getItem(`${key}-${hospitalCode}`)
}
// 删除院区级缓存
export const removeLocalStorage = (key, data) => {
  const hospitalCode = getHospitalCode()
  if (!isNull(localStorage.getItem(`${key}-${hospitalCode}`))) {
    localStorage.removeItem(`${key}-${hospitalCode}`)
  }
  if (!isNull(localStorage.getItem(`${key}`))) {
    localStorage.removeItem(`${key}`)
  }
}
/**
 * 应用部分
 */
// 设置与获取主题颜色
const key_main_color = 'main_color'
export const setMainColor = (value) => {
    setLocalStorage(key_main_color, value)
}
export const getMainColor = () => {
    return getLocalStorage(key_main_color)
}
// 设置与获取用户权限代码
const key_permission_codes = 'key_permission_codes'
export const setPermissionCodes = (data) => {
    setLocalStorage(key_permission_codes, data)
}
export const getPermissionCodes = () => {
    return getLocalStorage(key_permission_codes)
}
